package com.wh.wisdomsite.xbox.server.manager;

import com.wh.wisdomsite.xbox.core.security.ServiceAccessController;
import com.wh.wisdomsite.xbox.common.session.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 功能说明：
 * </pre>
 *
 * @author launchso
 * @version 1.0
 */
public class SampleServiceAccessController implements ServiceAccessController {

    private static final Log logger = LogFactory.getLog(SampleServiceAccessController.class);

    //可访问服务
    private static Map<String, List<String>> aclMap = new HashMap<String, List<String>>();
    //需要记录日志的服务
    private static Map<String, List<String>> logMap = new HashMap<String, List<String>>();

    /*static {
        ArrayList<String> serviceMethods = new ArrayList<String>();
        //serviceMethods.add("user.get");
        serviceMethods.add("mm.pr.read");
        serviceMethods.add("user.logon");
        serviceMethods.add("user.logout");
        aclMap.put("11", serviceMethods);
    }*/

    /**
     * *
     * 应用是否可以访问某方法
     *
     * @param appKey
     * @param method
     * @param version
     * @return
     */
    @Override
    public boolean isAppGranted(String appKey, String method, String version) {
        if (aclMap.containsKey(appKey)) {
            List<String> serviceMethods = aclMap.get(appKey);
            return serviceMethods.contains(method + "$" + version);
        } else {
            return false;
        }
    }

    @Override
    public boolean isUserGranted(Session session, String method, String version) {
        return true;
    }


    public Map<String, List<String>> getAccessControllerList() {
        return aclMap;
    }

    public void setAccessServiceMethod(Map<String, List<String>> aclMap) {
        SampleServiceAccessController.aclMap = aclMap;
    }

    public Map<String, List<String>> getLogMap() {
        return logMap;
    }

    public void setLogMap(Map<String, List<String>> logMap) {
        SampleServiceAccessController.logMap = logMap;
    }
}

